package com.coolwen.spring.jdbc.dao;

import com.coolwen.spring.jdbc.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;

/**
 * @author CoolWen
 * @version 2020-04-09 10:10
 */
@Repository
public class UserDao implements IUserDao {

    private JdbcTemplate jdbcTemplate;

    @Autowired
    public void init(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    @Override
    public void add(User user, int gid) {
        user.setGid(gid);
        this.jdbcTemplate.update(
                "insert into t_user (user_name,pass_word,nick_name,gid) values (?,?,?,?)",
                user.getUsername(), user.getPassword(), user.getNickname(), user.getGid());
    }

    @Override
    public void delete(int id) {

    }

    @Override
    public void update(User user) {

    }

    @Override
    public User load(int id) {
        return null;
    }
}
